class MonkeyContext;

#ifndef __MONKEYCONTEXT_H__
#define __MONKEYCONTEXT_H__

#include <js/jsapi.h>
#include <list>
#include "MonkeyRuntime.h"
#include "MonkeyError.h"


class MonkeyObject;

class MonkeyContext {
  private:
    JSContext *context;
    JSObject  *global;
    const MonkeyRuntime *runtime;
    std::list<MonkeyObject *> children;
    std::list<MonkeyError> errors;

    MonkeyContext(const MonkeyRuntime *rt);

  public:
    ~MonkeyContext();
    
    JSContext *jsContext() const;
    JSObject *jsObject() const;
    void AddObject(MonkeyObject *obj);

    void ClearErrors() { errors.empty(); }
    void AddError(MonkeyError error) { errors.push_back(error); }
    std::list<MonkeyError> GetErrors() { return errors; }

    std::string EvaluateScript(const char *script);
    bool ValidateScript(const char *script);
    
    friend class MonkeyRuntime;
};

#endif /* __MONKEYCONTEXT_H__ */
